﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using cpe.cpein.UI.UserCpeInServiceReference;

namespace cpe.cpein.UI.Controls
{
    /// <summary>
    /// Interaction logic for UCPotentialContact.xaml
    /// </summary>
    public partial class UCPotentialContact : UserControl
    {

        #region Variables declaration

        /// <summary>
        /// Connection to WebService User
        /// </summary>
        UsersServiceClient _userService = new UsersServiceClient();

        /// <summary>
        /// Current User.
        /// </summary>
        public User _currentUser { get; set; }

        #endregion
        
        #region Create and Open

        public UCPotentialContact()
        {
            InitializeComponent();
        }

        public UCPotentialContact(User currentUser)
        {
            InitializeComponent();
            this._currentUser = currentUser;
        }
        #endregion

        #region Event Methods

        /// <summary>
        /// Method fires when control is Loaded.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            loadPotentialContactList();
        }
        #endregion

        #region Methods

        /// <summary>
        /// Bind the datagrid
        /// </summary>
        /// <returns></returns>
        private void loadPotentialContactList(){
            if (this._currentUser != null)
            {
                Tools.Tools.BeginWaitStatus();
                List<User> userList = new List<User>();
                userList = this._userService.GetPotentialRelations(this._currentUser, this._currentUser);
                ContactGrid.ItemsSource = userList;
                Tools.Tools.EndWaitStatus();
            }
        
        }

        #endregion
    }
}
